package com.hongtech.modules.system.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hongtech.common.bean.Token;
import com.hongtech.modules.system.service.PermissionService;
import com.hongtech.modules.system.service.SysMenuService;

/**
 * 权限service实现
 */
@Service
public class PermissionServiceImpl implements PermissionService {

	private static final Logger logger = Logger.getLogger(PermissionServiceImpl.class);

	@Autowired
	private SysMenuService sysMenuService;

	@Override
	public boolean hasPermission(Token token, String permission) {
		if (token == null) {
			throw new RuntimeException("非法的用户");
		}
		List<String> permissionList = sysMenuService.listMenuIdsByUserId(token.getUid());
		if (permissionList.contains(permission)) {
			return true;
		}
		logger.warn(String.format("无[%s]访问权限,uid:%s", permission, token.getUid()));
		return false;
	}

}
